package com.cy.store.service.impl;

import com.cy.store.mapper.DistrictMapper;
import com.cy.store.pojo.District;
import com.cy.store.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PROJECT_NAME: store
 * @DESCRIPTION:
 * @USER: 28416
 * @DATE: 2022/11/5 16:43
 */
@Service
public class DistrictServiceImpl   implements IDistrictService {

    @Autowired
    DistrictMapper districtMapper;

    /**
     * 查询省市区的下属地区
     * @param parent
     * @return
     */
    @Override
    public List<District> getByParent(String parent) {
        List<District> byParent = districtMapper.findByParent(parent);
        //在进行网络数据传输时，为了尽量避免无效的数据的传输，可以将无效的数据设置为null，可以节省流量，另一方面提了效率
        for (District district : byParent) {
            district.setId(null);
            district.setParent(null);
        }
        return byParent;
    }

    /**
     * 查询省市区的名称
     * @param code
     * @return
     */
    @Override
    public String getNameByCode(String code) {
        return districtMapper.findNameByCode(code);
    }
}
